package com.ajz.manager.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.ajz.manager.dao.MemberDao;
import com.ajz.manager.entity.JwtMember;
import com.ajz.manager.entity.Member;

public class JwtUserDetailsServiceImpl implements UserDetailsService{
	@Autowired
	private MemberDao memberDao;
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		Member user = memberDao.findByLoginName(username);
        if (user == null) {
            throw new UsernameNotFoundException(String.format("No user found with username '%s'.", username));
        } else {
//            return new JwtUser(user.getLoginName(), user.getPassword(), user.getRoles().stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList()));
        	return new JwtMember(user.getLoginName(), user.getPassword(), null);
        }
	}

}
